class Tuple < ActiveRecord::Base
  has_and_belongs_to_many :stories
  has_many :blogs
  belongs_to :group
  belongs_to :tag
  
  def self.find_or_create_by_group_and_tag(group, tag)
    group_id = group ? group.id : nil
    tuple = find(:first, :conditions=>{:group_id=>group_id, :tag_id=>tag.id})
    if not tuple then
      tuple = create(:group=>group, :tag => tag)
    end    
    return tuple
  end
  
  def to_s
    group = self.group ? self.group.name+":" : ""
    tag = self.tag.name
    "#{group}#{tag}"
  end
end
